<?php

namespace App\Http\Validate\Common;

use App\Http\Validate\AbstractBaseValidate;
use App\Models\Common\CommonPushBindModel;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class CommonValidate extends AbstractBaseValidate
{
    function getRules(): array
    {
        // TODO: Implement getRules() method.
        return [];
    }

    function getAttributes(): array
    {
        // TODO: Implement getAttributes() method.
        return [];
    }

    function registerValidateRules(): void
    {
        // TODO: Implement registerValidateRules() method.
    }

    function getMessages(): array
    {
        // TODO: Implement getMessages() method.
        return [];
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public static function getConfigContentValidate(array $params)
    {
        return self::getInstance()->validate(
            ["module", "name"],
            $params,
            [
                "module" => self::stringValidateBuild(true, 120, 1),
                "name"   => self::stringValidateBuild(true, 120, 1)
            ]
        );
    }

    /**
     * @param array $params
     * @return MessageBag|object
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public static function devicePushBindValidate(array $params)
    {
        return self::getInstance()->validate(
            ["mobileBrand", "regId"],
            $params,
            [
                "mobileBrand" => self::intInValidateBuild(true, CommonPushBindModel::MOBILE_BRAND_TEXT, [0]),
                "regId"       => Rule::when(
                    ($params["mobileBrand"] ?? 0) > 0,
                    "required|string|min:1|max:180",
                    ""
                )
            ]
        );
    }
}
